<template>
	<view class="w-100">
		<view class="flex-1 mx-3 row-ac-fw mt-3">
			<view class="product-item mt-2 mb-4" v-for="(item,index) in productList" :key="index" @click="toGoodsDetails(item)">
				<view class="product-img">
					<image :src="item.image_list[0].url" mode=""></image>
				</view>
				<view class="flex-1 mx-2 mt-3 row-a-j-fc">
					<view class="font-s-35 font-w-600 in1line">{{ item.product_name }}</view>
					<view class="font-s-3 mt-1" v-if="item.price > 0">￥{{ item.price }}</view>
					<view class="font-s-3 mt-1" v-else>预售</view>
					<view class="font-s-3 mt-2 to-detail">查看详情</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		productListUrl
	} from '@/api/index'
	export default {
		data() {
			return {
				queryInfo: {
					category_id: '',
					page: 1,
					page_size: 10
				},
				productList: [],
				productTotal:''
			}
		},
		onLoad(options) {
			this.queryInfo.category_id = options.categoryId
			this.getProductList()
		},
		onReachBottom() {
			this.onReachBottomHandle();
		},
		methods:{
			getProductList() {
				this.$R.get(productListUrl, this.queryInfo).then(res => {
					console.log('9999', res.code);
					if (res.code == 200) {
						this.productList = res.data.list
						this.productTotal = res.data.total
					}
				})
			},
			onReachBottomHandle() {
				// 触底事件
				if (this.productTotal != this.productList.length) {
					this.queryInfo.page_size+=10;
					this.getProductList()
				}
			},
			toGoodsDetails(item){
				uni.navigateTo({
					url: '/pages/product/details?productId=' + item.id,
				});
			}
		}
	}
</script>

<style lang="scss">
	.product-item {
		width: 333rpx;
		height: 568rpx;
		margin-right: 24rpx;
	
		&:nth-child(2n) {
			margin-right: 0;
		}
	
		.product-img {
			width: 333rpx;
			height: 333rpx;
	
			image {
				width: 333rpx;
				height: 333rpx;
			}
		}
		.to-detail{
			padding-bottom: 6rpx;
			border-bottom: 2rpx solid #666;
		}
	}
</style>